import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'

import fileUploadService from '/@/api/cn/core/dirs/fileUploadService'

interface FileUploadState {
}

export const useFileUploadStore = defineStore({
  id: 'fileUpload',
  state: (): FileUploadState => ({
  }),
  getters: {
  },
  actions: {
    fileUpload(param: FormData): Promise<Res<string>> {
      return new Promise<Res<string>>((resolve, reject) => {
        fileUploadService.fileUpload(param).then((res: AxiosResponse<Res<string>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useFileUploadStoreWithout() {
  return useFileUploadStore(store)
}
